www.gusucode.com > VC++ 酒店管理系统-源码程序 > VC++ 酒店管理系统-源码程序/code/hotel2003/RoomDestine.cpp

    //Download by http://www.NewXing.com
// RoomDestine.cpp : implementation file
//

#include "stdafx.h"
#include "qq.h"
#include "RoomDestine.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CRoomDestine dialog


CRoomDestine::CRoomDestine(CWnd* pParent /*=NULL*/)
	: CDialog(CRoomDestine::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRoomDestine)
	m_DestineCerityType = 0;
	m_SexType = 0;
	//}}AFX_DATA_INIT
	nDestineRoomSum=0;
}


void CRoomDestine::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRoomDestine)
	DDX_Control(pDX, IDC_ROOMDESTINE_BILLCODE, m_BillCode);
	DDX_Control(pDX, IDC_ROOMDES_CERTIFYCODE, CerifyCode);
	DDX_Control(pDX, IDC_ROOMNUM, m_DestineRoomSum);
	DDX_Control(pDX, IDC_ROOMDESTINE_TYPE, m_RoomType);
	DDX_Control(pDX, IDC_ROOMDESTINE_TIME, m_DestineTime);
	DDX_Control(pDX, IDC_ROOMDESTINE_ROOMCODE, m_RoomCodeList);
	DDX_Control(pDX, IDC_ROOMDESTINE_PRICE, m_RoomPrice);
	DDX_Control(pDX, IDC_ROOMDESTINE_NAME, m_DestinerName);
	DDX_Control(pDX, IDC_ROOMDESTINE_MONEY, m_DestineMoney);
	DDX_Control(pDX, IDC_ROOMDESTINE_DESTINEBILL, m_DestineBill);
	DDX_Radio(pDX, IDC_RADIO1, m_DestineCerityType);
	DDX_Radio(pDX, IDC_RADIO4, m_SexType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRoomDestine, CDialog)
	//{{AFX_MSG_MAP(CRoomDestine)
	ON_CBN_SELCHANGE(IDC_ROOMDESTINE_TYPE, OnSelchangeRoomdestineType)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_DELETE, OnDelete)
	ON_BN_CLICKED(IDC_RADIO1, OnRadio)
	ON_BN_CLICKED(IDC_RADIO2, OnRadio)
	ON_BN_CLICKED(IDC_RADIO3, OnRadio)
	ON_BN_CLICKED(IDC_RADIO4, OnRadio)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRoomDestine message handlers

BOOL CRoomDestine::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_RoomType.SetWindowText("标准单人房");
	m_RoomType.AddString("标准单人房");//index==0
	m_RoomType.AddString("标准双人房");
	m_RoomType.AddString("贵族单人房");
	m_RoomType.AddString("贵族双人房");//index==3

	//产生帐单号码
	CCreateBillCode billcode;
	m_BillCode.SetWindowText(billcode.GenereBillCode());
	//////////////////////////////////////////////////////////////////////////
	CTime time=CTime::GetCurrentTime();//构造时间对象
    CTime tm(time);
	int year,month,day,hour,minute,second;
    year=tm.GetYear();
    month=tm.GetMonth();
	day=tm.GetDay();
	hour=tm.GetHour();
	minute=tm.GetMinute();
	second=tm.GetSecond();
	CString strYear,strMonth,strDay,strHour,strMinute,strSecond;
	strYear.Format("%d",year);
	strMonth.Format("%d",month);
	strDay.Format("%d",day);
	strHour.Format("%d",hour);
	strMinute.Format("%d",minute);
	strSecond.Format("%d",second);
	CString strShowText;
	strShowText=strYear+"-"+strMonth+"-"+strDay;
    strShowText=strShowText+" "+strHour+":"+strMinute+":"+strSecond;
    m_DestineTime.SetWindowText(strShowText);
	//设置预定额为0
	m_DestineMoney.SetWindowText("0");
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CRoomDestine::OnSelchangeRoomdestineType() 
{
	// TODO: Add your control notification handler code here
	m_RoomCodeList.ResetContent();//清除所有的项目
	CString strComboText;//combobox中的文本
    m_RoomType.GetLBText(m_RoomType.GetCurSel(),strComboText);//获得选择的文本
    /////////////////////////////////////////////////////////////////
    //	进行数据库的查询
    //roomprice fill
	CString SQLstr;
	SQLstr="SELECT * FROM RoomInfo where RoomType='" ;
    SQLstr=SQLstr+strComboText;
    SQLstr=SQLstr+"'";
	if(!m_RoomInfoSet.Open(AFX_DB_USE_DEFAULT_TYPE,SQLstr))
	{//查询数据库得到数据集合
		AfxMessageBox("打开数据库失败!");
		return ;
	}
	CString str;
	str.Format("%5.00f",m_RoomInfoSet.m_Price);
	m_RoomPrice.SetWindowText(str);
	m_RoomInfoSet.Close(); //关闭数据库 
	/////////////////////////////////////////////////////////////
	if(!m_RoomInfoSet.Open())
	{
		MessageBox("打开数据库失败!","数据库错误",MB_OK);
		return;
	}
	m_RoomInfoSet.MoveFirst();
	while(!m_RoomInfoSet.IsEOF())
	{
		if(m_RoomInfoSet.m_RoomType==strComboText)
		{
			if(m_RoomInfoSet.m_RoomStatus=="空")
			{
                m_RoomCodeList.AddString(m_RoomInfoSet.m_RoomCode);
			}
		}
		m_RoomInfoSet.MoveNext();
	}
	m_RoomInfoSet.Close();
	////////////////////////////////////////////////////////
	
	/////////////////////////////////////////////////////////////////////
}

void CRoomDestine::OnAdd() 
{
	// TODO: Add your control notification handler code here
	CString strRoomCode;
	if(m_RoomCodeList.GetCount()==0)
	{
		return;
	}
	else
	{
		if(m_RoomCodeList.GetCurSel()!=-1)
		{
           	m_RoomCodeList.GetText(m_RoomCodeList.GetCurSel(),strRoomCode);
		}
	}
	if(m_RoomCodeList.GetCurSel()==-1)
	{
		MessageBox("你至少要选择一项!","选择项为空",MB_OK);
		return;
	}
    if(m_RoomCodeList.GetCurSel()!=-1)
	{
		int n=m_DestineBill.GetCount();
		CString strTemp=" ";
		bool bSame=false;
		if(n!=0)
		{ 
			for(int i=0;i<n;i++)
			{
				m_DestineBill.GetText(i,strTemp);
				char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
				char* str=strtok(s," ");
				str=strtok(NULL," ");
				strTemp=str;
				if(strTemp==strRoomCode)
				{
					MessageBox("你已经添加了这个房间!","选择错误",MB_OK);
					bSame=true;
					return;
				}
			}
		}

		CString BillinfoText;
		if(!bSame)
		{
			m_RoomType.GetWindowText(BillinfoText);
			BillinfoText=BillinfoText+" "+strRoomCode;
			m_DestineBill.AddString(BillinfoText);
			nDestineRoomSum++;
			CString strSum;
			strSum.Format("%d",nDestineRoomSum);
			m_DestineRoomSum.SetWindowText(strSum);
			
		}
	}

	
	////////////////////////////////////////////////////////////////////

}

void CRoomDestine::OnDelete() 
{
	// TODO: Add your control notification handler code here
	int nCurSel=m_DestineBill.GetCurSel();
	if(nCurSel==-1)
	{
		MessageBox("请选择一个要删除的房间号","数据为空错误",MB_OK);
		return;
	}
	m_DestineBill.DeleteString(nCurSel);
    /////////更新显示
	nDestineRoomSum--;
	CString strSum;
	strSum.Format("%d",nDestineRoomSum);
	m_DestineRoomSum.SetWindowText(strSum);
}

void CRoomDestine::OnOK() 
{//  [7/1/2003-11:21]
	// TODO: Add extra validation here
	/*
	 *	将下面的一些代码放在OnOK()函数中是为了放在写入到数据库中时,证件类型或者
	    性别为空的情况的发生
		若在OnRaido()函数中写入这些代码,如果使用者没有点击Radio按钮的话,就不会进行
		赋值的操作,从而导致写入到数据库中的为空
	 */
	UpdateData(TRUE);//状态更新
	if(m_DestineCerityType==0)
	{
		m_CerityTypeName="身份证";
	}
	if(m_DestineCerityType==1)
	{
		m_CerityTypeName="军人证";
	}
	if(m_DestineCerityType==2)
	{
		m_CerityTypeName="学生证";
	}
	if(m_SexType==0)
	{
		m_DestinerSexType="男";
	}
	if(m_SexType==1)
	{
		m_DestinerSexType="女";
	}
	/*
	 *	先进行检查,看是否有些项目为空
	 */
	CString strDestinerName,strDestinerMoney,strCerityCode,strBillCode,strDestinetime;
	m_DestinerName.GetWindowText(strDestinerName);
	m_DestineMoney.GetWindowText(strDestinerMoney);
    CerifyCode.GetWindowText(strCerityCode);
    m_BillCode.GetWindowText(strBillCode);
    m_DestineTime.GetWindowText(strDestinetime);
	if(atof(strDestinerMoney)<0)
	{
		MessageBox("必须要缴纳预定金","预定金错误",MB_OK);
		return;
	}
	if(m_DestineBill.GetCount()==0)
	{
		MessageBox("帐单为空","错误",MB_OK);
		return;
	}
	if(strDestinerName==""||strDestinerMoney==""||strCerityCode=="")
	{
		MessageBox("请填写完整","为空错误",MB_OK);
		return;
	}
	////保存数据到数据库中
	if(!m_DestineRoomSet.Open())
	{
		MessageBox("数据库打开失败!","数据库错误",MB_OK);
		return;
	}
	bool bHadSameRecordSet=false;//是否已经有了这条记录
	m_DestineRoomSet.MoveFirst();
	while (!m_DestineRoomSet.IsEOF())
	{
		if(strCerityCode==m_DestineRoomSet.m_CeritifyCode)
		{
			bHadSameRecordSet=true;
			break;
		}
		m_DestineRoomSet.MoveNext();
	}
    m_DestineRoomSet.Close();//数据库关闭
	if(bHadSameRecordSet)
	{
		MessageBox("该客人已经预定了房间!","错误",MB_OK);
		return;
	}
	else
	{
		//写入到数据库的表中
		if(!m_DestineRoomSet.Open())
		{
			MessageBox("数据库打开失败!","数据库错误",MB_OK);
			return;
		}
		m_DestineRoomSet.AddNew();//添加一条新的记录
        m_DestineRoomSet.m_BillCode=strBillCode;//帐单号码
		m_DestineRoomSet.m_CeritifyCode=strCerityCode;
        m_DestineRoomSet.m_Certificate=m_CerityTypeName;
		m_DestineRoomSet.m_DestineMoney=strDestinerMoney;
		m_DestineRoomSet.m_DestinerName=strDestinerName;
		m_DestineRoomSet.m_DestinerSex=m_DestinerSexType;
		m_DestineRoomSet.m_DestineTime=strDestinetime;
		//写入预定了哪些房间
		CString strRoomCodes,strTemp;
		for(int i=0;i<m_DestineBill.GetCount();i++)
		{
			m_DestineBill.GetText(i,strTemp);
			char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
			char* str=strtok(s," ");
			str=strtok(NULL," ");
			strRoomCodes=strRoomCodes+str+",";
		}
		m_DestineRoomSet.m_DestineRoomCode=strRoomCodes;
		m_DestineRoomSet.Update();//更新记录
		m_DestineRoomSet.Close();//关闭数据库,写入了一条新的记录
		//改写CRoomInfoSet表中的信息
		//将预定的房间的状态改为“预定”
		for(i=0;i<m_DestineBill.GetCount();i++)
		{
			CString strRoomCode;
			m_DestineBill.GetText(i,strTemp);
			char* s=strTemp.GetBuffer(strTemp.GetLength());//there is a bug!
			char* str=strtok(s," ");
			str=strtok(NULL," ");
            strRoomCode=str;
            if(!m_RoomInfoSet.Open())
			{
			    MessageBox("数据库打开失败!","数据库错误",MB_OK);
			    return;
			}
		    m_RoomInfoSet.MoveFirst();
		    while (!m_RoomInfoSet.IsEOF())
			{
			    if(strRoomCode==m_RoomInfoSet.m_RoomCode)
				{
					m_RoomInfoSet.Edit();
					m_RoomInfoSet.m_RoomStatus="预定";
					m_RoomInfoSet.Update();
				}
				m_RoomInfoSet.MoveNext();
			}
			m_RoomInfoSet.Close();
		}
	}
	CDialog::OnOK();
}

void CRoomDestine::OnRadio() 
{
	// TODO: Add your control notification handler code here

}